import CURDHelper from '@/utils/CURDHelper'
import { VxeUI } from 'vxe-pc-ui';
import PageConfig from '@/utils/pageConfig'
import Query from '@/components/Query'
import XEUtils from 'xe-utils'

export default {
  name: 'ReportCustomer',
  components: {
    Query
  },
  data() {
    return {
      baseApiUrl: '/api/Report',
      componentSize: PageConfig.ComponentSize,
      duration: PageConfig.Duration,
      QueryConditions: [],
      QueryConfig: [{
        title: '客户名称',
        field: 'khmc',
        type: 'input',
        value: '',
        placeholder: '请输入客户名称以查询',
      }],
      GridOptions: {
        id: 'ReportCustomer_MainGrid',
        border: true,
        stripe: true,
        loading: false,
        size: PageConfig.ComponentSize,
        height: 700,
        showFooter: true,
        columnConfig: {
          resizable: true
        },
        rowConfig: {
          isHover: true,
          isCurrent: true
        },
        checkboxConfig: {
          highlight: true,
          range: true
        },
        customConfig: {
          mode: 'drawer',
          storage: true
        },
        footerData: [{
          htje:0,
          yskje: 0,
          sjskje: 0,
          ygq: 0,
          jgq: 0,
          djd: 0
        }],
        columns: [
          { type: 'seq', width: 50 },
          { type: 'checkbox', width: 35 },
          { field: 'khmc', title: '客户名称', sortable: true, minWidth: 120, showOverflow: true },
          { field: 'htje', title: '已签合同金额', sortable: true, minWidth: 120, showOverflow: true },
          { field: 'yskje', title: '应收款金额', sortable: true, minWidth: 120, showOverflow: true },
          { field: 'sjskje', title: '实收款金额', sortable: true, minWidth: 120, showOverflow: true },
          { field: 'ygq', title: '已过期(认证)', minWidth: 100, showOverflow: true },
          { field: 'jgq', title: '将过期(认证)', minWidth: 120, showOverflow: true },
          { field: 'djd1', title: '待监督一', minWidth: 120, showOverflow: true },
          { field: 'djd2', title: '待监督二', minWidth: 120, showOverflow: true },
        ],
        data: []
      },
      PagerConfig: {
        align: 'center',
        pageSize: 25,
        total: 0,
        currentPage: 1,
        pageSizes: [10, 25, 50, 100, 200],
      },
    }
  },
  created() {
    //this.InitOrder();
  },
  mounted(){
    
  },
  methods: {
    handleQuery(e) {
      this.QueryConditions = e;
      this.DoQuery(e);
    },
    handlePageChange() {
      this.DoQuery(this.QueryConditions);
    },
    DoQuery(e) {
      let request = {
        isPaging: true,
        pageSize: this.PagerConfig.pageSize,
        pageIndex: this.PagerConfig.currentPage,
        queryConditions: e,
        orderByConditions: []
      }
      CURDHelper.Query(request, `${this.baseApiUrl}/GetCustomReport`)
        .then(res => {
          this.GridOptions.data = res.data;
          this.PagerConfig.total = res.totalNumber;
          this.DoUpdateSummary();
        }).catch(err => {
          VxeUI.modal.message({
            content: err,
            status: 'error',
            duration: this.duration
          })
        })
    },
    DoUpdateSummary() {
      this.GridOptions.footerData[0].ygq = this.DoSum(this.GridOptions.data, 'ygq');
      this.GridOptions.footerData[0].yskje = this.DoSum(this.GridOptions.data, 'yskje');
      this.GridOptions.footerData[0].jgq = this.DoSum(this.GridOptions.data, 'jgq');
      this.GridOptions.footerData[0].djd1 = this.DoSum(this.GridOptions.data, 'djd1');
      this.GridOptions.footerData[0].djd2 = this.DoSum(this.GridOptions.data, 'djd2');
      this.GridOptions.footerData[0].sjskje = this.DoSum(this.GridOptions.data,'sjskje');
      this.GridOptions.footerData[0].htje = this.DoSum(this.GridOptions.data, 'htje');

    },
    DoSum(list, field) {
      let count = 0
      list.forEach(item => {
        count += Number(item[field])
      })
      return count.toFixed(2)
    },

  }
}
